package com.shrct.businessprocess.project;

import com.google.common.base.Objects;
import com.shrct.businessprocess.common.CurrencyType;
import com.shrct.businessprocess.common.impl.CurrencyTypeImpl;
import edu.fudan.mylang.pf.BaseDataType;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

public class RCRealMoney extends BaseDataType {
  public RCRealMoney() {
    super();
  }
  
  private Double amount;
  
  public Double getAmount() {
    return this.amount;
  }
  
  public RCRealMoney setAmount(final Double amount) {
    this.amount = amount;
    return this;			
    
  }
  
  @JoinColumn(name = "currencyType_id")
  @ManyToOne(targetEntity = CurrencyTypeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private CurrencyType currencyType;
  
  public CurrencyType getCurrencyType() {
    return this.currencyType;
  }
  
  public RCRealMoney setCurrencyType(final CurrencyType currencyType) {
    this.currencyType = currencyType;
    return this;			
    
  }
  
  private Double exchangeRate;
  
  public Double getExchangeRate() {
    return this.exchangeRate;
  }
  
  public RCRealMoney setExchangeRate(final Double exchangeRate) {
    this.exchangeRate = exchangeRate;
    return this;			
    
  }
  
  public RCRealMoney plus(final RCRealMoney m1, final CurrencyType hostCurrencyType) {
    RCRealMoney _xifexpression = null;
    boolean _notEquals = (!Objects.equal(m1.currencyType, this.currencyType));
    if (_notEquals) {
      RCRealMoney _rCRealMoney = new RCRealMoney();
      final Procedure1<RCRealMoney> _function = new Procedure1<RCRealMoney>() {
          public void apply(final RCRealMoney it) {
            double _multiply = DoubleExtensions.operator_multiply(RCRealMoney.this.amount, RCRealMoney.this.exchangeRate);
            double _multiply_1 = DoubleExtensions.operator_multiply(m1.amount, m1.exchangeRate);
            double _plus = (_multiply + _multiply_1);
            it.amount = Double.valueOf(_plus);
            it.currencyType = hostCurrencyType;
            it.exchangeRate = Double.valueOf(1d);
          }
        };
      RCRealMoney _doubleArrow = ObjectExtensions.<RCRealMoney>operator_doubleArrow(_rCRealMoney, _function);
      _xifexpression = _doubleArrow;
    } else {
      RCRealMoney _rCRealMoney_1 = new RCRealMoney();
      final Procedure1<RCRealMoney> _function_1 = new Procedure1<RCRealMoney>() {
          public void apply(final RCRealMoney it) {
            double _plus = DoubleExtensions.operator_plus(RCRealMoney.this.amount, m1.amount);
            it.amount = Double.valueOf(_plus);
            it.currencyType = RCRealMoney.this.currencyType;
            it.exchangeRate = RCRealMoney.this.exchangeRate;
          }
        };
      RCRealMoney _doubleArrow_1 = ObjectExtensions.<RCRealMoney>operator_doubleArrow(_rCRealMoney_1, _function_1);
      _xifexpression = _doubleArrow_1;
    }
    return _xifexpression;
  }
  
  public Double toHostAmount() {
    double _multiply = DoubleExtensions.operator_multiply(
      this.amount, this.exchangeRate);
    return Double.valueOf(_multiply);
  }
  
  public String toString() {
    String _string = this.amount.toString();
    String _xifexpression = null;
    String _codeid = this.currencyType.getCodeid();
    boolean _equals = _codeid.equals("01");
    if (_equals) {
      _xifexpression = "\u5143";
    } else {
      String _name = this.currencyType.getName();
      _xifexpression = _name;
    }
    String _plus = (_string + _xifexpression);
    return _plus;
  }
  
  public static RCRealMoney create() {
    return new RCRealMoney();
    
    
  }
}
